"""Prepare Trans10K dataset"""
import os
import torch
import numpy as np
import logging
from PIL import Image
from IPython import embed
import cv2


def get_boundary(mask, thicky=5):
	contour, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
	tempb = np.zeros_like(mask)
	tempb = cv2.drawContours(tempb, contour, -1, 255, thicky)
	return tempb


path_img = r"E:\Dataset\temp\skin\img\f1\ISIC_0000000.jpg"
path_mask = r"E:\Dataset\temp\skin\mask\f1\ISIC_0000000_segmentation.png"
path1 = r"E:\Dataset\temp\skin\boundary\f1\ISIC_0000000_segmentation.png"
path2 = r"E:\Dataset\temp\skin\boundary\f1\ISIC_0000000_boundary.png"


img = Image.open(path_img)
print(img.size)
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)

print(img.shape)
print(type(img))

mask = Image.open(path_mask)
print(mask.size)
mask = np.array(mask)
print(mask.shape)


contour, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

print(type(contour))
print(len(contour))

print(type(contour[0]))
print(contour[0].shape)

img2 = cv2.drawContours(img, contour, -1, (255, 0, 0), 2)

cv2.imshow("123", img2)

cv2.waitKey(0)

# mask2 = cv2.imread(path2)
# cv2.imshow("1233434", mask2)
# mask2 = cv2.resize(mask2, (256, 256))
# cv2.imshow("1233sdfsd434", mask2)
# print(mask.dtype)
# print(mask.shape)
#
# print(np.max(mask))
#
# mask = cv2.resize(mask, (256, 256))
# mask = np.array(mask)
# cv2.imshow("123", mask)
#
# boundary = get_boundary(mask)
# cv2.imshow("34", boundary)
# cv2.waitKey(0)

# path2 = path.replace("mask", "boundary")
# path2 = path2.replace("segmentation", "boundary")
# print(path2)
#
# cv2.imwrite(path2, boundary, [cv2.IMWRITE_PNG_COMPRESSION, 0])




